package com.ruoyi.crm.sale.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.sale.domain.CrmBusinessProduct;
import com.ruoyi.crm.sale.service.ICrmBusinessProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机产品关系Controller
 * 
 * @author ruoyi
 * @date 2021-09-14
 */
@RestController
@RequestMapping("/crm/busProduct")
public class CrmBusinessProductController extends BaseController
{
    @Autowired
    private ICrmBusinessProductService crmBusinessProductService;

    /**
     * 查询商机产品关系列表
     */
    @PreAuthorize("@ss.hasPermi('crm:busProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmBusinessProduct crmBusinessProduct)
    {
        List<CrmBusinessProduct> list = crmBusinessProductService.selectCrmBusinessProductList(crmBusinessProduct);
        return getDataTable(list);
    }

    /**
     * 导出商机产品关系列表
     */
    @PreAuthorize("@ss.hasPermi('crm:busProduct:export')")
    @Log(title = "商机产品关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmBusinessProduct crmBusinessProduct)
    {
        List<CrmBusinessProduct> list = crmBusinessProductService.selectCrmBusinessProductList(crmBusinessProduct);
        ExcelUtil<CrmBusinessProduct> util = new ExcelUtil<CrmBusinessProduct>(CrmBusinessProduct.class);
        return util.exportExcel(list, "商机产品关系数据");
    }

    /**
     * 获取商机产品关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:busProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmBusinessProductService.selectCrmBusinessProductById(id));
    }

    /**
     * 新增商机产品关系
     */
    @PreAuthorize("@ss.hasPermi('crm:busProduct:add')")
    @Log(title = "商机产品关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmBusinessProduct crmBusinessProduct)
    {
        return toAjax(crmBusinessProductService.insertCrmBusinessProduct(crmBusinessProduct));
    }

    /**
     * 修改商机产品关系
     */
    @PreAuthorize("@ss.hasPermi('crm:busProduct:edit')")
    @Log(title = "商机产品关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<CrmBusinessProduct> crmBusProductList)
    {
        return toAjax(crmBusinessProductService.updateCrmBusinessProduct(crmBusProductList));
    }

    /**
     * 删除商机产品关系
     */
    @PreAuthorize("@ss.hasPermi('crm:busProduct:remove')")
    @Log(title = "商机产品关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmBusinessProductService.deleteCrmBusinessProductByIds(ids));
    }
}
